From 52ab9943919ae03f5b4ee89db159a80cc195b454 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 22 Sep 2004 12:25:40 +0000 Subject: [PATCH] Quick start on a mindlessly simply parser test suite. Works on a standalone parser object, not through the globals or the web interface, which is created anew for each test. Pretty primitive so far, but this at least allows accumulation of tests for now. --- maintenance/parserTests.php | 106 ++++++++++++++++++++++++++++++++++++ maintenance/parserTests.txt | 60 ++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 maintenance/parserTests.php create mode 100644 maintenance/parserTests.txt diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php new file mode 100644 index 0000000000..14f0a04a4f --- /dev/null +++ b/maintenance/parserTests.php @@ -0,0 +1,106 @@ +runTest( + rtrim( $data['test'] ), + rtrim( $data['input'] ), + rtrim( $data['result'] ) ) ) { + $success++; + } + $total++; + $data = array(); + $section = null; + continue; + } + $data[$section] = ''; + continue; + } + if( $section ) { + $data[$section] .= $line; + } + } + if( $total > 0 ) { + $ratio = IntVal( 100.0 * $success / $total ); + print "\nPassed $success of $total tests ($ratio%)\n"; + } + } + + /** + * @param string $input Wikitext to try rendering + * @param string $result Result to output + * @return bool + */ + function runTest( $desc, $input, $result ) { + print "Running test $desc..."; + + $user =& new User(); + $options =& ParserOptions::newFromUser( $user ); + $parser =& new Parser(); + $title =& Title::makeTitle( NS_MAIN, 'Parser_test' ); + + $output =& $parser->parse( $input, $title, $options ); + + $html = $output->getText(); + # $languageLinks = $output->getLanguageLinks(); + # $categoryLinks = $output->getCategoryLinks(); + + if( $result == rtrim( $html ) ) { + return $this->showSuccess( $desc ); + } else { + return $this->showFailure( $desc, $result, $html ); + } + } + + function showSuccess( $desc ) { + print "ok\n"; + return true; + } + + function showFailure( $desc, $result, $html ) { + print "FAILED\n"; + print "!! Expected:\n$result\n"; + print "!! Received:\n$html\n!!\n"; + return false; + } +} + +$tester =& new ParserTest(); +$tester->runTestsFromFile( 'maintenance/parserTests.txt' ); + +?> \ No newline at end of file diff --git a/maintenance/parserTests.txt b/maintenance/parserTests.txt new file mode 100644 index 0000000000..d6c8e62976 --- /dev/null +++ b/maintenance/parserTests.txt @@ -0,0 +1,60 @@ +!! test +Blank input +!! input +!! result +!! end + +!! test +Simple paragraph +!! input +This is a simple paragraph. +!! result +

This is a simple paragraph. +

+!! end + +!! test +Simple list +!! input +* Item 1 +* Item 2 +!! result + +!! end + +!! test +Italics and bold +!! input +* plain +* plain''italic''plain +* plain''italic''plain''italic''plain +* plain'''bold'''plain +* plain'''bold'''plain'''bold'''plain +* plain''italic''plain'''bold'''plain +* plain'''bold'''plain''italic''plain +* plain''italic'''bold-italic'''italic''plain +* plain'''bold''bold-italic''bold'''plain +* plain'''''bold-italic'''italic''plain +* plain'''''bold-italic''bold'''plain +* plain''italic'''bold-italic'''''plain +* plain'''bold''bold-italic'''''plain +* plain l'''italic''plain +!! result + +!! end -- 2.20.1